/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package goodenglish.domain.model.lexicon;

import goodenglish.domain.service.Translator;
import goodenglish.infrastructure.EnTTS;
import goodenglish.infrastructure.repository.db.LexiconRepositoryDb;
import goodenglish.interfaces.BeanFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * @author 关攀攀 panpan_001@126.com
 */
public class NewWord implements Comparable<NewWord> {

	private static Log logger = LogFactory.getLog(NewWord.class);
	private String id;
	private String spell;
	private String explain;
	private String localExplain1;
	private String exampleSentStr;
	private boolean planed;

	public NewWord() {
	}

	public NewWord(String spell, String explain) {
		this.spell = spell;
		this.explain = explain;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public String getExplain() {
		return explain;
	}


	public boolean isPlaned() {
		return planed;
	}

	public void setPlaned(boolean planed) {
		this.planed = planed;
	}


	public String getShortExplain() {
		if (null == getExplain()) {
			return "";
		} else {
			return getExplain().split("\r\n")[0].split("\n")[0];
		}

	}

	public void setExplain(String explain) {
		this.explain = explain;
	}

	public String getSpell() {
		return spell;
	}

	public void setSpell(String spell) {
		this.spell = spell;
	}

	public String getLocalExplain1() {
		if (null == localExplain1) {
			this.localExplain1 = translator.englishToChiniseLocal(spell);
		}
		return localExplain1;
	}

	public void setExampleSentStr(String exampleSentStr) {
		this.exampleSentStr = exampleSentStr;
	}

	public String getExampleSentStr() {
		return exampleSentStr;
	}

	public void speek() {
		EnTTS.speak(spell);
	}

	@Override
	public boolean equals(Object obj) {
		NewWord word = (NewWord) obj;
		return word.getSpell().equals(this.getSpell());
	}

	public int compareTo(NewWord word) {
		return this.getSpell().compareTo(word.getSpell());
	}

	private Translator translator = BeanFactory.getSingleInstance(Translator.class);
	private LexiconRepository lexiconRepository = BeanFactory.getSingleInstance(LexiconRepositoryDb.class);
}
